﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VideoNetApplication.Common.Helper;
using VideoNetApplication.Common.Service;
using System.Text;
using VideoNetApplication.Common;

namespace VideoNetApplication.Control
{
    public partial class Navigation : BaseControl
    {
        public int nid = 0;
         
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["nid"] != null && StringUtils.IsNumeric(Request["nid"])  )
            {
                nid = Convert.ToInt32(Request["nid"]);
                
               
            }
          

            ResolveNavigation();
        }
        private void  ResolveNavigation()
        {
           
            
            string url = Request.Url.ToString();
            StringBuilder reurl =new StringBuilder();
            if (url.IndexOf("NewsDetail") > -1)
            {
                NewsService newsService = new NewsService();
                var news= newsService.GetNewsById(nid);
                if (news != null)
                {
                    reurl.AppendFormat(
                        "<a href=\"ViewNewsListHtml.aspx?schoolId={0}\" target=_blank>学校新闻</a> &gt; <a href=\"ViewNewsDetail.aspx?schoolId={0}&nid={1}\" target=_blank>{2}</a> ",
                        SchoolId, news.ID, news.NewsTitle);
                }

            }
            if(url.IndexOf("NewsList")>-1)
            {
                reurl.AppendFormat("<a href=\"ViewNewsListHtml.aspx?schoolId={0}\" target=_blank>学校新闻</a>", SchoolId);

            }
            if (url.IndexOf("RecruitList") > -1)
            {
                reurl.AppendFormat("<a href=\"ViewRecruitListHtml.aspx?schoolId={0}\" target=_blank>招生简章</a>", SchoolId);

            } 
            if (url.IndexOf("RecruitDetail") > -1)
            {
                RecruitStudentService recruitStudentService = new RecruitStudentService();
                var recruit = recruitStudentService.GetRecruitById(nid);
                if (recruit != null)
                {
                    reurl.AppendFormat(
                        "<a href=\"ViewRecruitListHtml.aspx?schoolId={0}\" target=_blank>招生简章</a> &gt; <a href=\"ViewRecruitDetail.aspx?schoolId={0}&nid={1}\" target=_blank>{2}</a> ",
                        SchoolId, nid, recruit.RecruitTitle);
                }

            }
            if (url.IndexOf("AllCourses") > -1)
            {
                reurl.AppendFormat("<a href=\"ViewAllCoursesHtml.aspx?schoolId={0}\" target=_blank>推荐课程</a>", SchoolId);

            }
            if (url.IndexOf("UpdateUserInfo")>-1)
            {
                reurl.AppendFormat("<a href=\"UpdateUserInfo.aspx?schoolId={0}\" target=_blank>修改个人信息</a>", SchoolId);
            
            }

            if (url.IndexOf("CourseDetail") > -1)
            {
                CourseService courseService = new CourseService();
                var course = courseService.GetCourseById(SchoolId, nid);
                if (course != null)
                {
                    reurl.AppendFormat(
                        "<a href=\"ViewAllCoursesHtml.aspx?schoolId={0}\" target=_blank>推荐课程</a> &gt; <a href=\"ViewCourseDetail.aspx?schoolId={0}&nid={1}\" target=_blank>{2}</a>",
                        SchoolId, course.ID, course.VC_name);
                }

            }
            if (url.IndexOf("TeacherList") > -1)
            {
                reurl.AppendFormat("<a href=\"ViewTeacherListHtml.aspx?schoolId={0}\" target=_blank>名师风采</a>", SchoolId);

            }
            if (url.IndexOf("TeacherDetail") > -1)
            {
                TeacherService teacherService=new TeacherService();
                var teacher = teacherService.GetTeacherByID(nid, SchoolId);
                if (teacher != null)
                {
                    reurl.AppendFormat(
                        "<a href=\"ViewTeacherListHtml.aspx?schoolId={0}\" target=_blank>名师风采</a> &gt; <a href=\"ViewTeacherDetail.aspx?schoolId={0}&nid={1}\" target=_blank>{2}</a> ",
                        SchoolId, nid, teacher.VT_realname);
                }
            }

            ltrNav.Text = reurl.ToString();


        }
    }
}